#include <stdio.h>
#include <malloc.h>
#include <stdbool.h>

#define ERROR 0
typedef int ElementType;

struct SNode{
    ElementType *data;
    int top;
    int MaxSize;
};
typedef struct SNode *Stack;
Stack createStack(int Maxsize) {
    Stack S = (Stack)malloc(sizeof (struct SNode));
    S->data = (ElementType*) malloc(Maxsize * sizeof (ElementType));
    S->top = 0;
    S->MaxSize = Maxsize;
    return S;
}
bool isFull(Stack S) {
    return (S->top == S->MaxSize );
}
bool Push(Stack S,ElementType x) {
    if(isFull(S)) {
        Stack *tmp = (ElementType*) realloc(S,sizeof (ElementType) * 2);
        S = tmp;

    }
    S->data[S->top] = x;
    S->top++;
    return true;


}
bool isEmpty(Stack S) {
    return (S->top == -1);
}
ElementType Pop(Stack S) {
    if(isFull(S)) {
        printf("堆栈空!");
        return ERROR;
    } else{
        int x = S->data[(S->top - 1)];
        S->top--;
        return x;
    }
}


int main() {
    Stack  s1;
    s1 = createStack(4);
    Push(s1,5);
    Push(s1,5);
    Push(s1,5);
    Push(s1,5);
    Push(s1,5);
    Push(s1,7);
    printf("%d\n", s1->data[s1->top-1]);
    int x = Pop(s1);
    printf("%d %d",x,s1->top);
    return 0;
}
